﻿#include "background.h"
#include "Checklists.h"
#include "OIS.h"
#include "MFD.h"

PIMAGE frame = newimage();
PIMAGE Frame = newimage();
PIMAGE RightButton = newimage(422, 1326);
PIMAGE LeftButton = newimage(428, 1303);


// 调用这个函数即可

void drawBackground(float x0, float y0, const ViewState& state) {

    //setbkcolor(WHITE, frame);
    float BackScale = state.scale;
    // drawSky(x0, y0, state);
     //{
     //    // test
     //    drawFrame(0, 0, state);
     //    //putimage(0, 0, frame);
     //    ege_drawimage(frame, 0, 0, 682.0f * BackScale, 560.0f * BackScale, 0, 0, 682.0f * BackScale, 466.0f * BackScale);
     //    drawCL(345, 47, 427 * BackScale);
     //}
     // Frame(PFD,ND)
    drawFrame(x0, y0, state);
    getimage_pngfile(Frame, ".\\resource\\png\\Frame.png");
    //drawFrameLong(x0, y0, state);
    //putimage(x0 + 1236.0f * BackScale, y0 + 762.0f * BackScale, frame);
    putimage_withalpha(NULL, Frame, x0 + 1238.0f * BackScale, y0 + 762.0f * BackScale, 682.0f * BackScale, 466.0f * BackScale, 0, 0, getwidth(Frame), getheight(Frame), true);

    // ND 右边的按钮
    getimage_pngfile(LeftButton, ".\\resource\\png\\LeftButton.png");
    putimage_rotatezoom(NULL, LeftButton, x0 + 1921.0f * BackScale, y0 + 762.0f * BackScale, 0, 0, 0, 465.0f * BackScale / 1303.0f, true, -1, true);

    setfillcolor(EGEARGB(255, 73, 77, 96));
    //ege_fillrect(x0 + 1921.0f * BackScale, y0 + 762.0f * BackScale, 148.0f * BackScale, 465.0f * BackScale);

    //drawleftbutton(x0 + 1858.0f * BackScale, y0 + 762.0f * BackScale, state);

    // EWD,SD
    //putimage(x0 + 2073.0f * BackScale, y0 + 762.0f * BackScale, frame);
    //putimage_rotatezoom(NULL, Frame, x0 + 2073.0f * BackScale, y0 + 762.0f * BackScale, 0, 0, 0, 466.0f * BackScale / 1193.0f, true, -1, true);
    putimage_withalpha(NULL, Frame, x0 + 2073.0f * BackScale, y0 + 762.0f * BackScale, 682.0f * BackScale, 466.0f * BackScale, 0, 0, getwidth(Frame), getheight(Frame), true);


    // OIS
    drawFrameWith3DEffectRight(x0 + 551.0f * BackScale, y0 + 760.0f * BackScale, state);

    // Checklists, MFD
    //drawFrameRotatedTop(x0 + 2244.0f * BackScale, y0 + 1230.0f * BackScale, state);
    drawFrameRotatedTop(x0 + 2416.0f * BackScale, y0 + 1230.0f * BackScale, state);

    // EWD,SD 右边的按钮

    getimage_pngfile(RightButton, ".\\resource\\png\\RightButton.png");
    putimage_rotatezoom(NULL, RightButton, x0 + 2758.0f * BackScale, y0 + 762.0f * BackScale, 0, 0, 0, 465.0f * BackScale / 1326.0f, true, -1, true);
    //setfillcolor(EGEARGB(255, 73, 77, 96));
    //ege_fillrect(x0 + 2758.0f * BackScale, y0 + 762.0f * BackScale, 148.0f * BackScale, 465.0f * BackScale);

    // 右边的PFD和ND
    //putimage(x0 + 2906.0f * BackScale, y0 + 762.0f * BackScale, frame);
    //putimage_rotatezoom(NULL, Frame, x0 + 2908.0f * BackScale, y0 + 762.0f * BackScale, 0, 0, 0, 466.0f * BackScale / 1193.0f, true, -1, true);
    putimage_withalpha(NULL, Frame, x0 + 2908.0f * BackScale, y0 + 762.0f * BackScale, 682.0f * BackScale, 466.0f * BackScale, 0, 0, getwidth(Frame), getheight(Frame), true);


    // 最右边的OIS
    drawFrameWith3DEffectLeft(x0 + 3594.0f * BackScale, y0 + 760.0f * BackScale, state);

    // 上面图形的绘制
    drawTop(x0, y0, state);
}

void drawFrame(double x0, double y0, const ViewState& state)
{
    double BackScale = state.scale;
    resize(frame, 682.0f * BackScale, 466.0f * BackScale);
    setbkcolor(EGEARGB(0, 43, 48, 61), frame);

    ege_setpattern_lineargradient(688.0f * BackScale, 0.0f * BackScale, EGEARGB(255, 91, 95, 115), 0.0f * BackScale, 466.0f * BackScale, EGEARGB(255, 45, 51, 66), frame);
    ege_fillrect(0.0f * BackScale, 0.0f * BackScale, 688.0f * BackScale, 466.0f * BackScale, frame);

    setcolor(BLACK, frame);
    setlinewidth(2.0f * BackScale, frame);
    ege_rectangle(0.0f, 0.0f, 688.0f * BackScale, 466.0f * BackScale, frame);

    setlinecolor(BLACK, frame);
    ege_line(0.0f, 351.0f * BackScale, 11.0f * BackScale, 351.0f * BackScale, frame);
    ege_line(673.0f, 351.0f * BackScale, 688.0f * BackScale, 351.0f * BackScale, frame);

    ege_point stroke[] = {
        149.0f * BackScale, 9.0f * BackScale,
        133.0f * BackScale, 23.0f * BackScale,
        10.0f * BackScale, 23.0f * BackScale,
        10.0f * BackScale, 442.0f * BackScale,
        24.0f * BackScale, 459.0f * BackScale,
        658.0f * BackScale, 459.0f * BackScale,
        672.0f * BackScale, 444.0f * BackScale,
        672.0f * BackScale, 23.0f * BackScale,
        548.0f * BackScale, 23.0f * BackScale,
        535.0f * BackScale, 9.0f * BackScale,
        149.0f * BackScale, 9.0f * BackScale,
    };
    setcolor(EGEARGB(255, 12, 13, 18), frame);
    setlinewidth(5.0f * BackScale, frame);
    ege_drawpoly(sizeof(stroke) / sizeof(stroke[0]), stroke, frame);

    //setfillcolor(EGEARGB(255, 45, 51, 66), frame);
   // ege_setpattern_lineargradient(672.0f * BackScale, 23.0f * BackScale, EGEARGB(255, 91, 95, 115), 10.0f * BackScale, 442.0f * BackScale, EGEARGB(255, 45, 51, 66), frame);
    ege_fillpoly(sizeof(stroke) / sizeof(stroke[0]), stroke, frame);

    //ege_point center = {
    //    660.0f * BackScale, 5.0f * BackScale
    //};
    //ellipsegradient(center, EGEARGB(255, 87, 89, 107), 141.0f * BackScale, 0.0f, 684.0f * BackScale, 0.0f * BackScale, );

    setfillcolor(BLACK, frame);
    ege_fillroundrect(165.0f * BackScale, 13.0f * BackScale, 25.0f * BackScale, 13 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, frame);
    ege_fillroundrect(203.0f * BackScale, 13.0f * BackScale, 25.0f * BackScale, 13 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, frame);
    ege_fillroundrect(509.0f * BackScale, 13.0f * BackScale, 25.0f * BackScale, 13 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, frame);
    setfillcolor(EGEARGB(255, 30, 33, 44), frame);
    ege_fillroundrect(55.0f * BackScale, 9.0f * BackScale, 42.0f * BackScale, 9 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, frame);
    ege_fillroundrect(587.0f * BackScale, 9.0f * BackScale, 42.0f * BackScale, 9 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, frame);

    setlinewidth(1 * BackScale, frame);
    setlinecolor(BLACK, frame);
    ege_line(0.0f, 351.0f * BackScale, 11.0f * BackScale, 351.0f * BackScale, frame);

    //ege_point inner[] = {
    //    69.0f * BackScale, 28.0f * BackScale,
    //    18.0f * BackScale, 450.0f * BackScale,
    //    670.0f * BackScale, 450.0f * BackScale,
    //    670.0f * BackScale, 26.0f * BackScale,
    //    18.0f * BackScale, 28.0f * BackScale,
    //};
    //setfillcolor(EGEARGB(255, 51, 54, 66), frame);
    //ege_fillpoly(sizeof(inner) / sizeof(inner[0]), inner, frame);
    //ege_drawpoly(sizeof(inner) / sizeof(inner[0]), inner, frame);

    setcolor(EGEARGB(255, 58, 60, 72), frame);
    setlinewidth(4.0f * BackScale, frame);
    ege_rectangle(21.0f * BackScale, 41.0f * BackScale, 641.0f * BackScale, 404.0f * BackScale, frame);

    setcolor(EGEARGB(255, 35, 39, 48), frame);
    setlinewidth(5.0f * BackScale, frame);
    ege_rectangle(25.0f * BackScale, 45.0f * BackScale, 633.0f * BackScale, 396.0f * BackScale, frame);

    setlinewidth(1 * BackScale, frame);
    setlinecolor(BLACK, frame);
    ege_line(19.0f * BackScale, 39.0f * BackScale, 28.0f * BackScale, 48.0f * BackScale, frame);
    ege_line(664.0f * BackScale, 39.0f * BackScale, 656.0f * BackScale, 48.0f * BackScale, frame);
    ege_line(19.0f * BackScale, 447.0f * BackScale, 28.0f * BackScale, 439.0f * BackScale, frame);
    ege_line(664.0f * BackScale, 447.0f * BackScale, 656.0f * BackScale, 439.0f * BackScale, frame);

    // 背景
    setfillcolor(EGEARGB(255, 0, 0, 0), frame);
    //setfillcolor(GREEN, frame);
    ege_fillrect(27.0f * BackScale, 47.0f * BackScale, 628.0f * BackScale, 391.0f * BackScale, frame);
    
    //// 创建临时图像
    //PIMAGE mask = newimage(628.0f * BackScale, 391.0f * BackScale);
    //setbkcolor(BLACK, mask); // 黑色作为透明色
    //cleardevice(mask);

    //// 复制原始内容到临时图像
    //getimage(mask, frame,
    //    27.0f * BackScale, 47.0f * BackScale,
    //    628.0f * BackScale, 391.0f * BackScale);

    //// 使用透明色覆盖
    //setbkcolor(EGERGBA(0, 0, 0, 0), mask);
    //cleardevice(mask);

    //// 将透明区域复制回原图像
    //putimage(frame, 27.0f * BackScale, 47.0f * BackScale, mask, SRCPAINT);

    // 清理资源
    //delimage(mask);
    setlinecolor(EGEARGB(255, 60, 72, 102), frame);
    setlinewidth(7 * BackScale, frame);
    ege_line(342.0f * BackScale, 52.0f * BackScale, 342.0f * BackScale, 434.0f * BackScale, frame);

}

void drawTop(float x0, float y0, const ViewState& state) {
    // 辅助直线
    //         x0 + 1861.0f * BackScale, y0 + 762.0f * BackScale,
    //         x0 + 1993.0f * BackScale, y0 + 730.0f * BackScale,
    float BackScale = state.scale;

    float delayx = 156.0f * BackScale; // 调整位置
    delayx = 0;
    ege_point top[] = {
        x0 + 4272.0f * BackScale - delayx, y0 + 762.0f * BackScale,
        x0 + 4304.0f * BackScale - delayx, y0 + 730.0f * BackScale,
        x0 + 488.0f * BackScale + delayx, y0 + 730.0f * BackScale,
        x0 + 560.0f * BackScale + delayx, y0 + 762.0f * BackScale,
    };
    //setcolor(BLACK);
    setfillcolor(EGEARGB(255, 37, 41, 53));
    //ege_drawpoly(sizeof(top) / sizeof(top[0]), top);
    ege_fillpoly(sizeof(top) / sizeof(top[0]), top);

    setfillcolor(EGEARGB(255, 86, 90, 109));
    ege_fillroundrect(x0 + 488.0f * BackScale + delayx, y0 + 715.0f * BackScale, 3816.0f * BackScale - 2 * delayx, 15.0f * BackScale, 0, 0, 10.0f * BackScale, 10.0f * BackScale);

    setlinewidth(3.0f * BackScale);
    setcolor(BLACK);
    ege_line(x0 + 1719.0f * BackScale, y0 + 731.0f * BackScale, x0 + 1856.0f * BackScale, y0 + 763.0f * BackScale);
    ege_line(x0 + 3103.0f * BackScale, y0 + 731.0f * BackScale, x0 + 2968.0f * BackScale, y0 + 762.0f * BackScale);

    setlinewidth(5.0f * BackScale);
    ege_line(x0 + 1719.0f * BackScale, y0 + 731.0f * BackScale, x0 + 1719.0f * BackScale, y0 + 715.0f * BackScale);
    ege_line(x0 + 3103.0f * BackScale, y0 + 731.0f * BackScale, x0 + 3103.0f * BackScale, y0 + 715.0f * BackScale);

    float offsetX = -276;  // 向左移动5个像素
    float offsetY = -18; // 向上移动20个像素

    ege_path left;

    // 定义正弦曲线路径点（角度范围从 -PI/2 到 PI/2）
    const int CURVE_POINT_COUNT = 30; // 曲线点数量

    // 计算总点数：原leftpanel有5个点，减去最后一个点，加上曲线点和终点
    const int TOTAL_POINT_COUNT = 5 - 1 + CURVE_POINT_COUNT + 1;
    ege_point leftpanel[TOTAL_POINT_COUNT];

    // 复制前四个点到新数组，并应用偏移
    leftpanel[0] = {
        x0 + (1988.0f + offsetX) * BackScale,
        y0 + (501.0f + offsetY) * BackScale
    };
    leftpanel[1] = {
        x0 + (1988.0f + offsetX) * BackScale,
        y0 + (725.0f + offsetY) * BackScale
    };
    leftpanel[2] = {
        x0 + (767.0f + offsetX) * BackScale + delayx,
        y0 + (725.0f + offsetY) * BackScale
    };
    leftpanel[3] = {
        x0 + (767.0f + offsetX) * BackScale + delayx,
        y0 + (633.0f + offsetY) * BackScale
    };

    // 计算正弦曲线上的点（角度从 -PI/2 到 PI/2），并应用偏移
    for (int i = 0; i < CURVE_POINT_COUNT; i++) {
        float t = (float)i / (CURVE_POINT_COUNT - 1); // t 从 0 到 1
        float x = 1745.0f + t * (1988.0f - 1745.0f) + offsetX;

        // 角度从 -PI/2 到 PI/2
        float angle = -M_PI / 2.0 + t * M_PI;

        // 计算y值并应用偏移
        float y = 567.0f - (633.0f - 501.0f) * sin(angle) / 2.0f + offsetY;

        leftpanel[4 + i] = {
            x0 + x * BackScale,
            y0 + y * BackScale
        };
    }

    // 添加终点并应用偏移
    leftpanel[TOTAL_POINT_COUNT - 1] = {
        x0 + (1988.0f + offsetX) * BackScale,
        y0 + (501.0f + offsetY) * BackScale
    };

    // 只需要添加一次多段线
    ege_path_addpolygon(&left, TOTAL_POINT_COUNT, leftpanel);

    setfillcolor(EGEARGB(255, 56, 61, 77));
    ege_fillpath(&left);

    setlinecolor(EGEARGB(255, 77, 81, 98));
    setlinewidth(9.0f * BackScale);
    ege_drawpath(&left);

    // 中间上面的
    ege_point topm[] = {
        x0 + 2000.0f * BackScale, y0 + 528.0f * BackScale,
        x0 + 3096.0f * BackScale, y0 + 528.0f * BackScale,
        x0 + 3096.0f * BackScale, y0 + 707.0f * BackScale,
        x0 + 2000.0f * BackScale, y0 + 707.0f * BackScale,
        x0 + 2000.0f * BackScale, y0 + 528.0f * BackScale,
    };

    setfillcolor(EGEARGB(255, 56, 61, 77));
    //ege_fillpoly(sizeof(topm) / sizeof(topm[0]), topm);

    setlinecolor(EGEARGB(255, 77, 81, 98));
    setlinewidth(9.0f * BackScale);
    //ege_drawpoly(sizeof(topm) / sizeof(topm[0]), topm);

    DrawInstrumentPanel(x0 + 1726.0f * BackScale, y0 + 483.0f * BackScale, 1370.0f * BackScale, 1370.0f * BackScale * 244 / 1494);

    // 右边的
    offsetX = -2;
    ege_point rightpanel[TOTAL_POINT_COUNT];

    rightpanel[0] = {
        x0 + (4303.0f + offsetX) * BackScale - delayx,
        y0 + (633.0f + offsetY) * BackScale
    };
    rightpanel[1] = {
        x0 + (4303.0f + offsetX) * BackScale - delayx,
        y0 + (725.0f + offsetY) * BackScale
    };
    rightpanel[2] = {
        x0 + (3112.0f + offsetX) * BackScale,
        y0 + (725.0f + offsetY) * BackScale
    };
    rightpanel[3] = {
        x0 + (3112.0f + offsetX) * BackScale,
        y0 + (501.0f + offsetY) * BackScale
    };
    for (int i = 0; i < CURVE_POINT_COUNT; i++) {
        float t = (float)i / (CURVE_POINT_COUNT - 1); // t 从 0 到 1

        // 起点坐标 (3112, 725)，终点假设为 (4603, 725)（x轴延伸）
        float startX = 3112.0f + offsetX;
        //float endX = 4603.0f;
        float x = startX + t * (243.0f); // x轴线性插值

        // 角度范围 PI/2 到 3PI/2（对应sin值从1到-1）
        float angle = t * M_PI;

        // 振幅不变（与之前一致：(633-546)/2 =）
        float amplitude = 66.0f;
        //float midY = startX == 3112.0f ? 725.0f - amplitude : 560.5f; // 中点y坐标
        float y = 567.0f - amplitude * cos(angle) + offsetY; // 正弦曲线计算

        rightpanel[4 + i] = {
            x0 + x * BackScale,
            y0 + y * BackScale
        };
    }

    // 添加终点并应用偏移
    rightpanel[TOTAL_POINT_COUNT - 1] = {
        x0 + (4303.0f + offsetX) * BackScale - delayx,
        y0 + (633.0f + offsetY) * BackScale
    };

    setfillcolor(EGEARGB(255, 56, 61, 77));
    ege_fillpoly(sizeof(rightpanel) / sizeof(rightpanel[0]), rightpanel);

    setlinecolor(EGEARGB(255, 77, 81, 98));
    setlinewidth(9.0f * BackScale);
    ege_drawpoly(sizeof(rightpanel) / sizeof(rightpanel[0]), rightpanel);

    // 表盘上面的绘制
    //{
    //    const int TOPNUM = 30;
    //    ege_point Shelf[TOPNUM + CURVE_POINT_COUNT];
    //    Shelf[0] = {
    //        x0 + (320.0f + offsetX) * BackScale,
    //        y0 + (622.0f + offsetY) * BackScale
    //    };
    //    Shelf[1] = {
    //        x0 + (324.0f + offsetX) * BackScale,
    //        y0 + (626.0f + offsetY) * BackScale
    //    };
    //    Shelf[2] = {
    //        x0 + (320.0f + offsetX) * BackScale,
    //        y0 + (632.0f + offsetY) * BackScale
    //    };
    //    Shelf[3] = {
    //        x0 + (379.0f + offsetX) * BackScale,
    //        y0 + (635.0f + offsetY) * BackScale
    //    };
    //    Shelf[4] = {
    //        x0 + (403.0f + offsetX) * BackScale,
    //        y0 + (634.0f + offsetY) * BackScale
    //    };
    //    Shelf[5] = {
    //        x0 + (447.0f + offsetX) * BackScale,
    //        y0 + (631.0f + offsetY) * BackScale
    //    };
    //    Shelf[6] = {
    //        x0 + (495.0f + offsetX) * BackScale,
    //        y0 + (633.0f + offsetY) * BackScale
    //    };
    //    Shelf[7] = {
    //        x0 + (1754.0f + offsetX) * BackScale,
    //        y0 + (633.0f + offsetY) * BackScale
    //    };

    //    for (int i = 0; i < CURVE_POINT_COUNT; i++) {
    //        float t = (float)i / (CURVE_POINT_COUNT - 1); // t 从 0 到 1
    //        float x = 1754.0f + t * (1988.0f - 1754.0f) + offsetX;

    //        // 角度从 -PI/2 到 PI/2
    //        float angle = -M_PI / 2.0 + t * M_PI / 2.0;

    //        // 计算y值并应用偏移
    //        float y = 560.5f - (633.0f - 488.0f) * sin(angle) / 2.0f + offsetY - 10.0f;

    //        Shelf[8 + i] = {
    //            x0 + x * BackScale,
    //            y0 + y * BackScale
    //        };
    //    }
    //}

    ege_point p1[] = {
        x0 + 495.0f * BackScale, y0 + 730.0f * BackScale,
        x0 + 495.0f * BackScale, y0 + 740.0f * BackScale,
        x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,
        x0 + 559.0f * BackScale, y0 + 763.0f * BackScale,
        x0 + 495.0f * BackScale, y0 + 730.0f * BackScale,

    };

    ////从文件中加载图片
    //PIMAGE pimg = newimage(400, 400);
    //getimage(pimg, "cabin.png");

    ////将图片生成纹理
    //ege_gentexture(true, pimg);
    ////对图片设置透明度
    //ege_setalpha(0xFF, pimg);
    ////设置为纹理填充
    //ege_setpattern_texture(pimg, 0, 0, 400, 400);

    //ege_fillpoly(sizeof(p1) / sizeof(p1[0]), p1);

    //setlinecolor(EGEARGB(255, 0, 0, 0));
    //setlinewidth(2.0f * BackScale);
    //ege_drawpoly(sizeof(p1) / sizeof(p1[0]), p1);

    //ege_point p2[] = {
    //    x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,
    //    x0 + 481.0f * BackScale, y0 + 755.0f * BackScale,
    //    x0 + 326.0f * BackScale, y0 + 754.0f * BackScale,
    //    x0 + 335.0f * BackScale, y0 + 849.0f * BackScale,
    //    x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,

    //};

    //ege_fillpoly(sizeof(p2) / sizeof(p2[0]), p2);
    //ege_drawpoly(sizeof(p2) / sizeof(p2[0]), p2);

    //float r = 163.0f * BackScale;
    //ege_fillpie(x0 + 488.0f * BackScale - r, y0 + 740.0f * BackScale - r, r * 2.0, r * 2.0, 180, 90);
    //ege_pie(x0 + 488.0f * BackScale - r, y0 + 740.0f * BackScale - r, r * 2.0, r * 2.0, 180, 90);

    //ege_point p3[] = {
    //    x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,
    //    x0 + 495.0f * BackScale, y0 + 740.0f * BackScale,
    //    x0 + 495.0f * BackScale, y0 + 730.0f * BackScale,
    //    x0 + 488.0f * BackScale, y0 + 730.0f * BackScale,
    //    x0 + 488.0f * BackScale, y0 + 740.0f * BackScale,
    //    x0 + 488.0f * BackScale - r, y0 + 740.0f * BackScale,
    //    x0 + 326.0f * BackScale, y0 + 754.0f * BackScale,
    //    x0 + 481.0f * BackScale, y0 + 755.0f * BackScale,
    //    x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,
    //};

    //setfillcolor(EGEARGB(255, 49, 51, 61));
    //ege_fillpoly(sizeof(p3) / sizeof(p3[0]), p3);

    //delimage(pimg);

    //ege_point p4[] = {
    //    x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,
    //    x0 + 559.0f * BackScale, y0 + 763.0f * BackScale,
    //    x0 + 1173.0f * BackScale, y0 + 762.0f * BackScale,
    //    x0 + 559.0f * BackScale, y0 + 825.0f * BackScale,

    //};
    //setfillcolor(EGEARGB(255, 26, 29, 40));
    //ege_fillpoly(sizeof(p4) / sizeof(p4[0]), p4);

}

//void drawFrameLong(double x0, double y0, const ViewState& state)
//{
//    double BackScale = state.scale;
//    float lenth = 150.0f * BackScale;
//    resize(frame, 682.0f * BackScale + lenth, 466.0f * BackScale);
//    //setbkcolor(EGEARGB(255, 43, 48, 61), frame);
//
//    ege_setpattern_lineargradient(688.0f * BackScale + lenth, 0.0f * BackScale, EGEARGB(255, 91, 95, 115), 0.0f * BackScale, 466.0f * BackScale, EGEARGB(255, 45, 51, 66), frame);
//    ege_fillrect(0.0f * BackScale, 0.0f * BackScale, 688.0f * BackScale + lenth, 466.0f * BackScale, frame);
//    
//    setcolor(BLACK, frame);
//    setlinewidth(2.0f * BackScale, frame);
//    ege_rectangle(0.0f, 0.0f, 688.0f * BackScale + lenth, 466.0f * BackScale, frame);
//
//    setlinecolor(BLACK, frame);
//    ege_line(0.0f, 351.0f * BackScale, 11.0f * BackScale, 351.0f * BackScale, frame);
//    ege_line(673.0f + lenth, 351.0f * BackScale, 688.0f * BackScale + lenth, 351.0f * BackScale, frame);
//
//    ege_point stroke[] = {
//        149.0f * BackScale, 9.0f * BackScale,
//        133.0f * BackScale, 23.0f * BackScale,
//        10.0f * BackScale, 23.0f * BackScale,
//        10.0f * BackScale, 442.0f * BackScale,
//        24.0f * BackScale, 459.0f * BackScale,
//        658.0f * BackScale + lenth, 459.0f * BackScale,
//        672.0f * BackScale + lenth, 444.0f * BackScale,
//        672.0f * BackScale + lenth, 23.0f * BackScale,
//        548.0f * BackScale + lenth, 23.0f * BackScale,
//        535.0f * BackScale + lenth, 9.0f * BackScale,
//        149.0f * BackScale, 9.0f * BackScale,
//    };
//    setcolor(EGEARGB(255, 12, 13, 18), frame);
//    setlinewidth(5.0f * BackScale, frame);
//    ege_drawpoly(sizeof(stroke) / sizeof(stroke[0]), stroke, frame);
//
//    //setfillcolor(EGEARGB(255, 45, 51, 66), frame);
//   // ege_setpattern_lineargradient(672.0f * BackScale + lenth, 23.0f * BackScale, EGEARGB(255, 91, 95, 115), 10.0f * BackScale, 442.0f * BackScale, EGEARGB(255, 45, 51, 66), frame);
//    ege_fillpoly(sizeof(stroke) / sizeof(stroke[0]), stroke, frame);
//
//
//    //ege_point center = {
//    //    660.0f * BackScale, 5.0f * BackScale
//    //};
//    //ellipsegradient(center, EGEARGB(255, 87, 89, 107), 141.0f * BackScale, 0.0f, 684.0f * BackScale, 0.0f * BackScale, );
//
//    setfillcolor(BLACK, frame);
//    ege_fillroundrect(165.0f * BackScale, 13.0f * BackScale, 25.0f * BackScale, 13 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, frame);
//    ege_fillroundrect(203.0f * BackScale, 13.0f * BackScale, 25.0f * BackScale, 13 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, frame);
//    ege_fillroundrect(509.0f * BackScale + lenth, 13.0f * BackScale, 25.0f * BackScale, 13 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, 3 * BackScale, frame);
//    setfillcolor(EGEARGB(255, 30, 33, 44), frame);
//    ege_fillroundrect(55.0f * BackScale, 9.0f * BackScale, 42.0f * BackScale, 9 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, frame);
//    ege_fillroundrect(587.0f * BackScale + lenth, 9.0f * BackScale, 42.0f * BackScale, 9 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, 2 * BackScale, frame);
//
//    setlinewidth(1 * BackScale, frame);
//    setlinecolor(BLACK, frame);
//    ege_line(0.0f, 351.0f * BackScale, 11.0f * BackScale, 351.0f * BackScale, frame);
//
//    //ege_point inner[] = {
//    //    69.0f * BackScale, 28.0f * BackScale,
//    //    18.0f * BackScale, 450.0f * BackScale,
//    //    670.0f * BackScale, 450.0f * BackScale,
//    //    670.0f * BackScale, 26.0f * BackScale,
//    //    18.0f * BackScale, 28.0f * BackScale,
//    //};
//    //setfillcolor(EGEARGB(255, 51, 54, 66), frame);
//    //ege_fillpoly(sizeof(inner) / sizeof(inner[0]), inner, frame);
//    //ege_drawpoly(sizeof(inner) / sizeof(inner[0]), inner, frame);
//
//    setcolor(EGEARGB(255, 58, 60, 72), frame);
//    setlinewidth(4.0f * BackScale, frame);
//    ege_rectangle(21.0f * BackScale, 41.0f * BackScale, 641.0f * BackScale + lenth, 404.0f * BackScale, frame);
//
//    setcolor(EGEARGB(255, 35, 39, 48), frame);
//    setlinewidth(5.0f * BackScale, frame);
//    ege_rectangle(25.0f * BackScale, 45.0f * BackScale, 633.0f * BackScale + lenth, 396.0f * BackScale, frame);
//
//    setlinewidth(1 * BackScale, frame);
//    setlinecolor(BLACK, frame);
//    ege_line(19.0f * BackScale, 39.0f * BackScale, 28.0f * BackScale, 48.0f * BackScale, frame);
//    ege_line(664.0f * BackScale + lenth, 39.0f * BackScale, 656.0f * BackScale + lenth, 48.0f * BackScale, frame);
//    ege_line(19.0f * BackScale, 447.0f * BackScale, 28.0f * BackScale, 439.0f * BackScale, frame);
//    ege_line(664.0f * BackScale + lenth, 447.0f * BackScale, 656.0f * BackScale + lenth, 439.0f * BackScale, frame);
//
//    // 背景
//    //setfillcolor(BLACK, frame);
//    setfillcolor(GREEN, frame);
//    ege_fillrect(27.0f * BackScale, 47.0f * BackScale, 628.0f * BackScale + lenth, 391.0f * BackScale, frame);
//
//    //setlinecolor(EGEARGB(255, 60, 72, 102), frame);
//    //setlinewidth(7 * BackScale, frame);
//    //ege_line(342.0f * BackScale + lenth, 52.0f * BackScale, 342.0f * BackScale + lenth, 434.0f * BackScale, frame);
//
//}

void drawFrameWith3DEffectRight(double x0, double y0, const ViewState& state) {

    drawFrame(0, 0, state);

    const double angle = 11.0 * PI / 180.0;
    const double BackScale = state.scale;
    const int baseWidth = 688/* + 150*/; // 合并计算

    // 尺寸计算优化
    const int width = static_cast<int>(baseWidth * BackScale);
    const int height = static_cast<int>(466 * BackScale);
    const int extraHeight = static_cast<int>(height * sin(fabs(angle)));
    const int newHeight = height + extraHeight;

    PIMAGE transformed = newimage();


    setbkmode(TRANSPARENT, transformed);

    resize(transformed, width, newHeight);
    setbkcolor(EGEARGB(0, 0, 0, 0), transformed);
    //cleardevice(transformed);

    drawOIS(0, 0, 391.0f * BackScale);
    putimage(frame, 55.0f * BackScale, 47.5f * BackScale, oisImg);

    // 抗锯齿处理核心逻辑
    for (int y = 0; y < newHeight; ++y) {
        for (int x = 0; x < width; ++x) {
            double ratio = static_cast<double>(x) / width;
            double srcY_f = y - (height * (1.0 - ratio) * sin(angle));

            // 双线性插值采样
            if (srcY_f >= 0 && srcY_f < height - 1) {
                int srcX = x;
                int y1 = static_cast<int>(srcY_f);
                int y2 = y1 + 1;
                double alpha = srcY_f - y1;

                color_t c1 = getpixel(srcX, y1, frame);
                color_t c2 = getpixel(srcX, y2, frame);

                // 混合颜色
                color_t blended = RGB(
                    static_cast<int>((1 - alpha) * GetRValue(c1) + alpha * GetRValue(c2)),
                    static_cast<int>((1 - alpha) * GetGValue(c1) + alpha * GetGValue(c2)),
                    static_cast<int>((1 - alpha) * GetBValue(c1) + alpha * GetBValue(c2))
                );
                putpixel(x, y, blended, transformed);
            }
            else {
                // 超出原图像范围的区域设为透明
                putpixel(x, y, EGEARGB(0, 0, 0, 0), transformed);
            }
        }
    }

    putimage(x0, y0, transformed);
    delimage(transformed);
}

void drawFrameWith3DEffectLeft(double x0, double y0, const ViewState& state) {
    drawFrame(0, 0, state);

    const double angle = 5.0 * PI / 180.0;
    const double backScale = state.scale;
    const int originalWidth = 688/* + 150*/;
    const int originalHeight = 466;

    // 尺寸计算优化
    const int width = static_cast<int>(originalWidth * backScale);
    const int height = static_cast<int>(originalHeight * backScale);
    const int extraHeight = static_cast<int>(originalWidth * tan(fabs(angle)) * backScale);
    const int newHeight = height + extraHeight;

    PIMAGE transformed = newimage();
    resize(transformed, width, newHeight);
    setbkcolor(EGEARGB(0, 0, 0, 0), transformed);
    cleardevice(transformed);

    drawOIS(0, 0, 391.0f * backScale);
    putimage(frame, 55.0f * backScale, 47.5f * backScale, oisImg);


    // 抗锯齿处理核心逻辑
    for (int y = 0; y < newHeight; ++y) {
        for (int x = 0; x < width; ++x) {
            double relX = static_cast<double>(x) / width;
            double tiltOffset = relX * originalWidth * tan(angle) * backScale;
            double srcY_f = y - tiltOffset;

            // 双线性插值采样
            if (srcY_f >= 0 && srcY_f < height - 1) {
                int srcX = x;
                int y1 = static_cast<int>(srcY_f);
                int y2 = y1 + 1;
                double alpha = srcY_f - y1;

                color_t c1 = getpixel(srcX, y1, frame);
                color_t c2 = getpixel(srcX, y2, frame);

                // 混合颜色
                color_t blended = RGB(
                    static_cast<int>((1 - alpha) * GetRValue(c1) + alpha * GetRValue(c2)),
                    static_cast<int>((1 - alpha) * GetGValue(c1) + alpha * GetGValue(c2)),
                    static_cast<int>((1 - alpha) * GetBValue(c1) + alpha * GetBValue(c2))
                );
                putpixel(x, y, blended, transformed);
            }
        }
    }

    putimage(x0, y0, transformed);
    delimage(transformed);
}

void drawFrameRotatedTop(double x0, double y0, const ViewState& state)
{
    // 1. 初始化阶段
    drawFrame(0, 0, state);
    bool enableAA = true;
    const double BackScale = state.scale;
    const int origWidth = static_cast<int>(688 * BackScale);
    const int origHeight = static_cast<int>(466 * BackScale);

    // 透视参数 - 可调整这两个值控制俯视效果强度
    const double perspectiveFactor = 0.3; // 透视强度因子
    const double bottomExtension = origWidth * perspectiveFactor; // 底部延伸总宽度

    // 抗锯齿增强参数
    const int supersample = 2; // 超采样倍率
    const double blurRadius = 0.8; // 边缘模糊半径

    // 2. 创建倒置图像
    PIMAGE inverted = newimage();
    resize(inverted, origWidth, origHeight);
    setbkcolor(EGEARGB(0, 0, 0, 0), inverted); // 修改：使用RGB颜色
    cleardevice(inverted);

    for (int y = 0; y < origHeight; ++y) {
        const int invertedY = origHeight - 1 - y;
        for (int x = 0; x < origWidth; ++x) {
            putpixel(x, y, getpixel(x, invertedY, frame), inverted);
        }
    }

    // 绘制基础元素
    drawMFD(0, 0, 391.0f * BackScale);
    drawCL(0, 0, 391.0f * BackScale, (360.0f - 340.0f) * BackScale + x0, 29.0f * BackScale + y0);
    putimage(inverted, 360.0f * BackScale, 29.0f * BackScale, ckl);
    putimage(inverted, 40.0f * BackScale, 29.0f * BackScale, mfdImg);

    // 3. 计算透视变形参数
    const int newWidth = origWidth + static_cast<int>(bottomExtension); // 新图像宽度
    const double halfExtension = bottomExtension / 2.0; // 底部单侧延伸宽度

    // 4. 创建目标图像
    PIMAGE transformed = newimage();
    resize(transformed, newWidth, origHeight);
    setbkcolor(EGEARGB(0, 0, 0, 0), transformed); // 修改：使用RGB颜色
    cleardevice(transformed);

    // 5. 增强抗锯齿透视变形处理
    if (enableAA) {
        // 双线性插值 + 超采样 + 边缘模糊
        for (int y = 0; y < origHeight; ++y) {
            // 计算当前行的宽度（线性插值）
            const double currentWidth = origWidth + 2 * halfExtension * y / (origHeight - 1);
            const double scaleX = currentWidth / origWidth; // 水平缩放因子
            const double offsetX = (newWidth - currentWidth) / 2; // 水平偏移

            for (int x = 0; x < newWidth; ++x) {
                // 线性映射到源图像坐标
                const double srcX_f = (x - offsetX) / scaleX;
                const double srcY_f = y;

                // 全双线性插值 (考虑四个相邻像素)
                if (srcX_f >= 1 && srcX_f < origWidth - 2 && srcY_f >= 1 && srcY_f < origHeight - 2) {
                    // 计算四个最近的整数坐标点
                    const int x1 = static_cast<int>(srcX_f);
                    const int y1 = static_cast<int>(srcY_f);
                    const int x2 = x1 + 1;
                    const int y2 = y1 + 1;

                    // 计算小数部分
                    const double fx = srcX_f - x1;
                    const double fy = srcY_f - y1;

                    // 采样四个点的颜色
                    color_t c11 = getpixel(x1, y1, inverted);
                    color_t c21 = getpixel(x2, y1, inverted);
                    color_t c12 = getpixel(x1, y2, inverted);
                    color_t c22 = getpixel(x2, y2, inverted);

                    // 双线性插值（修改：移除透明度相关计算）
                    const int r1 = static_cast<int>((1 - fx) * GetRValue(c11) + fx * GetRValue(c21));
                    const int g1 = static_cast<int>((1 - fx) * GetGValue(c11) + fx * GetGValue(c21));
                    const int b1 = static_cast<int>((1 - fx) * GetBValue(c11) + fx * GetBValue(c21));

                    const int r2 = static_cast<int>((1 - fx) * GetRValue(c12) + fx * GetRValue(c22));
                    const int g2 = static_cast<int>((1 - fx) * GetGValue(c12) + fx * GetGValue(c22));
                    const int b2 = static_cast<int>((1 - fx) * GetBValue(c12) + fx * GetBValue(c22));

                    const int r = static_cast<int>((1 - fy) * r1 + fy * r2);
                    const int g = static_cast<int>((1 - fy) * g1 + fy * g2);
                    const int b = static_cast<int>((1 - fy) * b1 + fy * b2);

                    putpixel(x, y, RGB(r, g, b), transformed);
                }
                // 边缘区域使用超采样
                else if (srcX_f >= blurRadius && srcX_f < origWidth - blurRadius - 1 &&
                    srcY_f >= blurRadius && srcY_f < origHeight - blurRadius - 1) {

                    int r = 0, g = 0, b = 0;
                    int samples = 0;

                    // 超采样 (在小区域内多次采样取平均)
                    for (int sy = -supersample; sy <= supersample; sy++) {
                        for (int sx = -supersample; sx <= supersample; sx++) {
                            const double sampleX = srcX_f + sx * blurRadius / supersample;
                            const double sampleY = srcY_f + sy * blurRadius / supersample;

                            if (sampleX >= 0 && sampleX < origWidth && sampleY >= 0 && sampleY < origHeight) {
                                // 对每个采样点进行双线性插值
                                const int x1 = static_cast<int>(sampleX);
                                const int y1 = static_cast<int>(sampleY);
                                const int x2 = x1 + 1;
                                const int y2 = y1 + 1;

                                if (x2 < origWidth && y2 < origHeight) {
                                    const double fx = sampleX - x1;
                                    const double fy = sampleY - y1;

                                    color_t c11 = getpixel(x1, y1, inverted);
                                    color_t c21 = getpixel(x2, y1, inverted);
                                    color_t c12 = getpixel(x1, y2, inverted);
                                    color_t c22 = getpixel(x2, y2, inverted);

                                    const int r1 = static_cast<int>((1 - fx) * GetRValue(c11) + fx * GetRValue(c21));
                                    const int g1 = static_cast<int>((1 - fx) * GetGValue(c11) + fx * GetGValue(c21));
                                    const int b1 = static_cast<int>((1 - fx) * GetBValue(c11) + fx * GetBValue(c21));

                                    const int r2 = static_cast<int>((1 - fx) * GetRValue(c12) + fx * GetRValue(c22));
                                    const int g2 = static_cast<int>((1 - fx) * GetGValue(c12) + fx * GetGValue(c22));
                                    const int b2 = static_cast<int>((1 - fx) * GetBValue(c12) + fx * GetBValue(c22));

                                    const int sr = static_cast<int>((1 - fy) * r1 + fy * r2);
                                    const int sg = static_cast<int>((1 - fy) * g1 + fy * g2);
                                    const int sb = static_cast<int>((1 - fy) * b1 + fy * b2);

                                    r += sr;
                                    g += sg;
                                    b += sb;
                                    samples++;
                                }
                            }
                        }
                    }

                    if (samples > 0) {
                        putpixel(x, y, RGB(r / samples, g / samples, b / samples), transformed);
                    }
                }
            }
        }

        //// 后处理：对边缘进行轻微模糊以进一步消除锯齿（修改：移除透明度判断）
        //PIMAGE temp = newimage();
        //resize(temp, newWidth, origHeight);
        //// 修改：使用EGE支持的copyimage方式
        //for (int y = 0; y < origHeight; y++) {
        //    for (int x = 0; x < newWidth; x++) {
        //        putpixel(x, y, getpixel(x, y, transformed), temp);
        //    }
        //}

        //for (int y = 1; y < origHeight - 1; y++) {
        //    for (int x = 1; x < newWidth - 1; x++) {
        //        // 修改：通过相邻像素是否为背景色判断边缘
        //        color_t c = getpixel(x, y, temp);
        //        bool isEdge = (getpixel(x - 1, y, temp) == RGB(0, 0, 0) ||
        //            getpixel(x + 1, y, temp) == RGB(0, 0, 0) ||
        //            getpixel(x, y - 1, temp) == RGB(0, 0, 0) ||
        //            getpixel(x, y + 1, temp) == RGB(0, 0, 0));

        //        if (isEdge) {
        //            int r = 0, g = 0, b = 0;
        //            int count = 0;

        //            // 3x3 区域模糊
        //            for (int dy = -1; dy <= 1; dy++) {
        //                for (int dx = -1; dx <= 1; dx++) {
        //                    color_t nc = getpixel(x + dx, y + dy, temp);
        //                    r += GetRValue(nc);
        //                    g += GetGValue(nc);
        //                    b += GetBValue(nc);
        //                    count++;
        //                }
        //            }

        //            if (count > 0) {
        //                putpixel(x, y, RGB(r / count, g / count, b / count), transformed);
        //            }
        //        }
        //    }
        //}

        //delimage(temp);
    }
    else {
        // 非抗锯齿版本保持不变
        for (int y = 0; y < origHeight; ++y) {
            const double currentWidth = origWidth + 2 * halfExtension * y / (origHeight - 1);
            const double scaleX = currentWidth / origWidth;
            const double offsetX = (newWidth - currentWidth) / 2;

            for (int x = 0; x < newWidth; ++x) {
                const double srcX_f = (x - offsetX) / scaleX;
                const int srcX = static_cast<int>(srcX_f);
                const int srcY = y;

                if (srcX >= 0 && srcX < origWidth && srcY >= 0 && srcY < origHeight) {
                    putpixel(x, y, getpixel(srcX, srcY, inverted), transformed);
                }
            }
        }
    }

    // 6. 最终输出
    putimage(x0 - newWidth / 2, y0, transformed);

    // 7. 资源清理
    delimage(transformed);
    delimage(inverted);
}

//void drawSky(double x0, double y0, const ViewState& state) {
//    double BackScale = state.scale;
//
//    ege_point Sky[] = {
//        x0 + 442.0f * BackScale, y0 + 0.0f * BackScale,
//        x0 + 420.0f * BackScale, y0 + 14.0f * BackScale,
//        x0 + 367.0f * BackScale, y0 + 60.0f * BackScale,
//        x0 + 444.0f * BackScale, y0 + 491.0f * BackScale,
//        x0 + 510.0f * BackScale, y0 + 592.0f * BackScale,
//        x0 + 767.0f * BackScale, y0 + 591.0f * BackScale,
//        x0 + 801.0f * BackScale, y0 + 587.0f * BackScale,
//        x0 + 1713.0f * BackScale, y0 + 580.0f * BackScale,
//        x0 + 1845.0f * BackScale, y0 + 515.0f * BackScale,
//        x0 + 2109.0f * BackScale, y0 + 29.0f * BackScale,
//        x0 + 2122.0f * BackScale, y0 + 27.0f * BackScale,
//        x0 + 2135.0f * BackScale, y0 + 0.0f * BackScale
//    };
//    setfillcolor(EGEARGB(255, 128, 164, 202));
//    ege_fillpoly(sizeof(Sky) / sizeof(Sky[0]) , Sky);
//}

//#define M_PI 3.1415926535

// 比例转换宏
#define SCALE_X(val) (x + (int)((val) * scaleX))
#define SCALE_Y(val) (y + (int)((val) * scaleY))
#define SCALE_W(val) (int)((val) * scaleX)
#define SCALE_H(val) (int)((val) * scaleY)

void DrawInstrumentPanel(int x, int y, int width, int height) {
    float scaleX = width / 1494.0f;
    float scaleY = height / 244.0f;

    ege_enable_aa(TRUE);
    setfillcolor(EGEARGB(255, 56, 61, 77));
    ege_fillroundrect(x, y, width, height, SCALE_W(10));
    setcolor(EGEARGB(255, 77, 81, 98));
    setlinewidth(SCALE_W(6));
    ege_roundrect(x, y, width, height, SCALE_W(10));

    // Button1 函数内容
    setfillcolor(EGERGB(30, 31, 34));
    setcolor(EGERGB(19, 20, 21));
    setlinewidth(SCALE_W(3));
    ege_fillroundrect(SCALE_X(31), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(31), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(75), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(75), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(31), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(31), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(75), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(75), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(144), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(144), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(204), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(204), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(263), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(263), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(322), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(322), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(380), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(380), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(144), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(144), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(204), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(204), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(263), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(263), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(322), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(322), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(380), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(380), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(742), SCALE_Y(83), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_roundrect(SCALE_X(742), SCALE_Y(83), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_fillroundrect(SCALE_X(713), SCALE_Y(137), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_roundrect(SCALE_X(713), SCALE_Y(137), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_fillroundrect(SCALE_X(770), SCALE_Y(137), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_roundrect(SCALE_X(770), SCALE_Y(137), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_fillroundrect(SCALE_X(642), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(642), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(833), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(833), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(743), SCALE_Y(190), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_roundrect(SCALE_X(743), SCALE_Y(190), SCALE_W(36), SCALE_H(37), SCALE_W(4));
    ege_fillroundrect(SCALE_X(970), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(970), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1431), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1431), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1387), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1387), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1431), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1431), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1387), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1387), SCALE_Y(208), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1318), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1318), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1258), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1258), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1199), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1199), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1140), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1140), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1082), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1082), SCALE_Y(12), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1318), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1318), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1258), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1258), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1199), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1199), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1140), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1140), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_fillroundrect(SCALE_X(1082), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));
    ege_roundrect(SCALE_X(1082), SCALE_Y(116), SCALE_W(36), SCALE_H(28), SCALE_W(4));


    // window1 函数内容
    setfillcolor(EGERGB(0, 0, 0));
    setcolor(EGERGB(88, 88, 88));
    setlinewidth(SCALE_W(3));
    ege_fillrect(SCALE_X(28), SCALE_Y(49), SCALE_W(392), SCALE_H(55));
    ege_fillrect(SCALE_X(481), SCALE_Y(49), SCALE_W(224), SCALE_H(55));
    ege_line(SCALE_X(133), SCALE_Y(49), SCALE_X(133), SCALE_Y(103));
    ege_line(SCALE_X(133), SCALE_Y(78), SCALE_X(420), SCALE_Y(78));
    ege_line(SCALE_X(193), SCALE_Y(78), SCALE_X(193), SCALE_Y(103));
    ege_line(SCALE_X(373), SCALE_Y(78), SCALE_X(373), SCALE_Y(103));
    ege_fillrect(SCALE_X(809), SCALE_Y(49), SCALE_W(224), SCALE_H(55));
    ege_fillrect(SCALE_X(1071), SCALE_Y(49), SCALE_W(392), SCALE_H(55));
    ege_line(SCALE_X(1361), SCALE_Y(49), SCALE_X(1361), SCALE_Y(103));
    ege_line(SCALE_X(1361), SCALE_Y(78), SCALE_X(1074), SCALE_Y(78));
    ege_line(SCALE_X(1301), SCALE_Y(78), SCALE_X(1301), SCALE_Y(103));
    ege_line(SCALE_X(1121), SCALE_Y(78), SCALE_X(1121), SCALE_Y(103));

    // drawline 函数内容
    setcolor(EGERGB(150, 150, 150));
    setlinewidth(SCALE_W(2));
    ege_line(SCALE_X(155), SCALE_Y(30), SCALE_X(163), SCALE_Y(35));
    ege_line(SCALE_X(163), SCALE_Y(35), SCALE_X(171), SCALE_Y(30));
    ege_line(SCALE_X(155), SCALE_Y(128), SCALE_X(163), SCALE_Y(123));
    ege_line(SCALE_X(163), SCALE_Y(123), SCALE_X(171), SCALE_Y(128));
    ege_line(SCALE_X(214), SCALE_Y(30), SCALE_X(222), SCALE_Y(35));
    ege_line(SCALE_X(222), SCALE_Y(35), SCALE_X(230), SCALE_Y(30));
    ege_line(SCALE_X(214), SCALE_Y(128), SCALE_X(222), SCALE_Y(123));
    ege_line(SCALE_X(222), SCALE_Y(123), SCALE_X(230), SCALE_Y(128));
    ege_line(SCALE_X(273), SCALE_Y(30), SCALE_X(281), SCALE_Y(35));
    ege_line(SCALE_X(281), SCALE_Y(35), SCALE_X(289), SCALE_Y(30));
    ege_line(SCALE_X(273), SCALE_Y(128), SCALE_X(281), SCALE_Y(123));
    ege_line(SCALE_X(281), SCALE_Y(123), SCALE_X(289), SCALE_Y(128));
    ege_line(SCALE_X(332), SCALE_Y(30), SCALE_X(340), SCALE_Y(35));
    ege_line(SCALE_X(340), SCALE_Y(35), SCALE_X(348), SCALE_Y(30));
    ege_line(SCALE_X(332), SCALE_Y(128), SCALE_X(340), SCALE_Y(123));
    ege_line(SCALE_X(340), SCALE_Y(123), SCALE_X(348), SCALE_Y(128));
    ege_line(SCALE_X(391), SCALE_Y(30), SCALE_X(399), SCALE_Y(35));
    ege_line(SCALE_X(399), SCALE_Y(35), SCALE_X(407), SCALE_Y(30));
    ege_line(SCALE_X(391), SCALE_Y(128), SCALE_X(399), SCALE_Y(123));
    ege_line(SCALE_X(399), SCALE_Y(123), SCALE_X(407), SCALE_Y(128));
    ege_line(SCALE_X(1091), SCALE_Y(30), SCALE_X(1100), SCALE_Y(35));
    ege_line(SCALE_X(1100), SCALE_Y(35), SCALE_X(1108), SCALE_Y(30));
    ege_line(SCALE_X(1091), SCALE_Y(128), SCALE_X(1100), SCALE_Y(123));
    ege_line(SCALE_X(1100), SCALE_Y(123), SCALE_X(1108), SCALE_Y(128));
    ege_line(SCALE_X(1150), SCALE_Y(30), SCALE_X(1159), SCALE_Y(35));
    ege_line(SCALE_X(1159), SCALE_Y(35), SCALE_X(1167), SCALE_Y(30));
    ege_line(SCALE_X(1150), SCALE_Y(128), SCALE_X(1159), SCALE_Y(123));
    ege_line(SCALE_X(1159), SCALE_Y(123), SCALE_X(1167), SCALE_Y(128));
    ege_line(SCALE_X(1209), SCALE_Y(30), SCALE_X(1217), SCALE_Y(35));
    ege_line(SCALE_X(1217), SCALE_Y(35), SCALE_X(1225), SCALE_Y(30));
    ege_line(SCALE_X(1209), SCALE_Y(128), SCALE_X(1217), SCALE_Y(123));
    ege_line(SCALE_X(1217), SCALE_Y(123), SCALE_X(1225), SCALE_Y(128));
    ege_line(SCALE_X(1268), SCALE_Y(30), SCALE_X(1276), SCALE_Y(35));
    ege_line(SCALE_X(1276), SCALE_Y(35), SCALE_X(1284), SCALE_Y(30));
    ege_line(SCALE_X(1268), SCALE_Y(128), SCALE_X(1276), SCALE_Y(123));
    ege_line(SCALE_X(1276), SCALE_Y(123), SCALE_X(1284), SCALE_Y(128));
    ege_line(SCALE_X(1327), SCALE_Y(30), SCALE_X(1335), SCALE_Y(35));
    ege_line(SCALE_X(1335), SCALE_Y(35), SCALE_X(1343), SCALE_Y(30));
    ege_line(SCALE_X(1327), SCALE_Y(128), SCALE_X(1335), SCALE_Y(123));
    ege_line(SCALE_X(1335), SCALE_Y(123), SCALE_X(1343), SCALE_Y(128));

    // drawButton 函数内容
    setfillcolor(EGERGB(93, 95, 99));
    setcolor(EGERGB(60, 60, 60));
    setlinewidth(SCALE_W(1));
    ege_fillcircle(SCALE_X(524), SCALE_Y(168), SCALE_W(27));
    ege_circle(SCALE_X(524), SCALE_Y(168), SCALE_W(27));
    setcolor(EGERGB(150, 150, 150));
    ege_circle(SCALE_X(524), SCALE_Y(168), SCALE_W(29));
    setfillcolor(EGERGB(87, 90, 97));
    ege_fillcircle(SCALE_X(518), SCALE_Y(171), SCALE_W(25));
    setlinewidth(SCALE_W(1));
    setcolor(EGERGB(20, 20, 20));
    ege_circle(SCALE_X(518), SCALE_Y(171), SCALE_W(26));
    ege_circle(SCALE_X(518), SCALE_Y(171), SCALE_W(1));
    setfillcolor(EGERGB(93, 95, 99));
    setcolor(EGERGB(60, 60, 60));
    setlinewidth(SCALE_W(1));
    ege_fillcircle(SCALE_X(990), SCALE_Y(168), SCALE_W(27));
    ege_circle(SCALE_X(990), SCALE_Y(168), SCALE_W(27));
    setcolor(EGERGB(150, 150, 150));
    ege_circle(SCALE_X(990), SCALE_Y(168), SCALE_W(29));
    setfillcolor(EGERGB(87, 90, 97));
    ege_fillcircle(SCALE_X(996), SCALE_Y(171), SCALE_W(25));
    setlinewidth(SCALE_W(1));
    setcolor(EGERGB(20, 20, 20));
    ege_circle(SCALE_X(996), SCALE_Y(171), SCALE_W(26));
    ege_circle(SCALE_X(996), SCALE_Y(171), SCALE_W(1));
    setfillcolor(EGERGB(93, 95, 99));
    setcolor(EGERGB(60, 60, 60));
    setlinewidth(SCALE_W(1));
    ege_fillcircle(SCALE_X(660), SCALE_Y(168), SCALE_W(27));
    ege_circle(SCALE_X(660), SCALE_Y(168), SCALE_W(27));
    setcolor(EGERGB(150, 150, 150));
    ege_circle(SCALE_X(660), SCALE_Y(168), SCALE_W(29));
    setfillcolor(EGERGB(87, 90, 97));
    ege_fillcircle(SCALE_X(660), SCALE_Y(171), SCALE_W(25));
    setlinewidth(SCALE_W(1));
    setcolor(EGERGB(20, 20, 20));
    ege_circle(SCALE_X(660), SCALE_Y(171), SCALE_W(26));
    ege_circle(SCALE_X(660), SCALE_Y(171), SCALE_W(1));

    // DrawWordandNumbers 函数内容
    settextjustify(LEFT_TEXT, TOP_TEXT);
    setfont(SCALE_H(13), SCALE_W(5), "MS UI Gothic");
    setcolor(EGERGB(165, 167, 169));
    ege_outtextxy(SCALE_X(473), SCALE_Y(20), " MACH");
    ege_outtextxy(SCALE_X(553), SCALE_Y(20), " SPD");
    ege_outtextxy(SCALE_X(609), SCALE_Y(20), " TRUE");
    ege_outtextxy(SCALE_X(675), SCALE_Y(20), " MAG");
    ege_outtextxy(SCALE_X(723), SCALE_Y(20), " HDG");
    ege_outtextxy(SCALE_X(776), SCALE_Y(20), " V/S");
    ege_outtextxy(SCALE_X(754), SCALE_Y(105), "FD");
    ege_outtextxy(SCALE_X(726), SCALE_Y(159), "AP1");
    ege_outtextxy(SCALE_X(782), SCALE_Y(159), "AP2");
    ege_outtextxy(SCALE_X(653), SCALE_Y(222), "LOC");
    ege_outtextxy(SCALE_X(745), SCALE_Y(211), "A/THR");
    ege_outtextxy(SCALE_X(847), SCALE_Y(223), "ALT");
    ege_outtextxy(SCALE_X(973), SCALE_Y(223), "APPR");
    ege_outtextxy(SCALE_X(816), SCALE_Y(129), "100");
    ege_outtextxy(SCALE_X(871), SCALE_Y(130), "1000");
    ege_outtextxy(SCALE_X(946), SCALE_Y(140), "UP");
    ege_outtextxy(SCALE_X(946), SCALE_Y(185), "DN");
    ege_outtextxy(SCALE_X(728), SCALE_Y(54), "TRK");
    ege_outtextxy(SCALE_X(780), SCALE_Y(54), "FPA");
    ege_outtextxy(SCALE_X(18), SCALE_Y(124), "in Hg");
    ege_outtextxy(SCALE_X(92), SCALE_Y(124), " hPa");
    ege_outtextxy(SCALE_X(148), SCALE_Y(191), " LS");
    ege_outtextxy(SCALE_X(152), SCALE_Y(165), " VOR");
    ege_outtextxy(SCALE_X(186), SCALE_Y(151), " NAV");
    ege_outtextxy(SCALE_X(223), SCALE_Y(164), " ARC");
    ege_outtextxy(SCALE_X(234), SCALE_Y(190), " V/S");
    ege_outtextxy(SCALE_X(38), SCALE_Y(27), "TAXI");
    ege_outtextxy(SCALE_X(43), SCALE_Y(221), "LS");
    ege_outtextxy(SCALE_X(88), SCALE_Y(221), "W");
    ege_outtextxy(SCALE_X(307), SCALE_Y(220), "ZOOM");
    ege_outtextxy(SCALE_X(317), SCALE_Y(189), "10");
    ege_outtextxy(SCALE_X(327), SCALE_Y(169), "20");
    ege_outtextxy(SCALE_X(346), SCALE_Y(153), "40");
    ege_outtextxy(SCALE_X(372), SCALE_Y(154), "80");
    ege_outtextxy(SCALE_X(396), SCALE_Y(169), "160");
    ege_outtextxy(SCALE_X(404), SCALE_Y(191), "320");
    ege_outtextxy(SCALE_X(394), SCALE_Y(211), "640");
    setfont(SCALE_H(13), SCALE_W(6), "MS UI Gothic");
    setcolor(EGERGB(255, 255, 255));
    ege_outtextxy(SCALE_X(47), SCALE_Y(54), "QNH");
    ege_outtextxy(SCALE_X(510), SCALE_Y(51), "SPD");
    ege_outtextxy(SCALE_X(621), SCALE_Y(51), "MAG");
    ege_outtextxy(SCALE_X(663), SCALE_Y(51), "HDG");
    ege_outtextxy(SCALE_X(848), SCALE_Y(51), "ALT");
    ege_outtextxy(SCALE_X(976), SCALE_Y(51), "V/S");
    ege_outtextxy(SCALE_X(554), SCALE_Y(88), "KT");
    setfont(SCALE_H(17), SCALE_W(7), "MS UI Gothic");
    setcolor(EGERGB(255, 255, 255));
    ege_outtextxy(SCALE_X(139), SCALE_Y(58), "CSTR");
    ege_outtextxy(SCALE_X(200), SCALE_Y(58), "WPT");
    ege_outtextxy(SCALE_X(252), SCALE_Y(58), "VORD");
    ege_outtextxy(SCALE_X(321), SCALE_Y(58), "NDB");
    ege_outtextxy(SCALE_X(375), SCALE_Y(58), "APPT");
    ege_outtextxy(SCALE_X(144), SCALE_Y(85), "VOR");
    ege_outtextxy(SCALE_X(207), SCALE_Y(85), "WX");
    ege_outtextxy(SCALE_X(259), SCALE_Y(85), "TERR");
    ege_outtextxy(SCALE_X(319), SCALE_Y(85), "TRAF");
    ege_outtextxy(SCALE_X(379), SCALE_Y(85), "VOR");
    setfont(SCALE_H(13), SCALE_W(5), "MS UI Gothic");
    setcolor(EGERGB(165, 167, 169));
    ege_outtextxy(SCALE_X(1364), SCALE_Y(124), "in Hg");
    ege_outtextxy(SCALE_X(1440), SCALE_Y(124), " hPa");
    ege_outtextxy(SCALE_X(1081), SCALE_Y(191), " LS");
    ege_outtextxy(SCALE_X(1085), SCALE_Y(165), " VOR");
    ege_outtextxy(SCALE_X(1119), SCALE_Y(151), " NAV");
    ege_outtextxy(SCALE_X(1156), SCALE_Y(164), " ARC");
    ege_outtextxy(SCALE_X(1167), SCALE_Y(190), " V/S");
    ege_outtextxy(SCALE_X(1433), SCALE_Y(27), "TAXI");
    ege_outtextxy(SCALE_X(1439), SCALE_Y(221), "LS");
    ege_outtextxy(SCALE_X(1396), SCALE_Y(221), "W");
    ege_outtextxy(SCALE_X(1240), SCALE_Y(220), "ZOOM");
    ege_outtextxy(SCALE_X(1250), SCALE_Y(189), "10");
    ege_outtextxy(SCALE_X(1260), SCALE_Y(169), "20");
    ege_outtextxy(SCALE_X(1279), SCALE_Y(153), "40");
    ege_outtextxy(SCALE_X(1305), SCALE_Y(154), "80");
    ege_outtextxy(SCALE_X(1329), SCALE_Y(169), "160");
    ege_outtextxy(SCALE_X(1337), SCALE_Y(191), "320");
    ege_outtextxy(SCALE_X(1327), SCALE_Y(211), "640");
    setfont(SCALE_H(13), SCALE_W(6), "MS UI Gothic");
    setcolor(EGERGB(255, 255, 255));
    ege_outtextxy(SCALE_X(1379), SCALE_Y(54), "QNH");
    setfont(SCALE_H(17), SCALE_W(7), "MS UI Gothic");
    setcolor(EGERGB(255, 255, 255));
    ege_outtextxy(SCALE_X(1072), SCALE_Y(58), "CSTR");
    ege_outtextxy(SCALE_X(1133), SCALE_Y(58), "WPT");
    ege_outtextxy(SCALE_X(1185), SCALE_Y(58), "VORD");
    ege_outtextxy(SCALE_X(1254), SCALE_Y(58), "NDB");
    ege_outtextxy(SCALE_X(1308), SCALE_Y(58), "APPT");
    ege_outtextxy(SCALE_X(1077), SCALE_Y(85), "VOR");
    ege_outtextxy(SCALE_X(1140), SCALE_Y(85), "WX");
    ege_outtextxy(SCALE_X(1192), SCALE_Y(85), "TERR");
    ege_outtextxy(SCALE_X(1252), SCALE_Y(85), "TRAF");
    ege_outtextxy(SCALE_X(1312), SCALE_Y(85), "VOR");
    setfont(SCALE_H(34), SCALE_W(15), "MS UI Gothic");
    setcolor(EGERGB(255, 255, 255));
    ege_outtextxy(SCALE_X(491), SCALE_Y(67), "100");
    ege_outtextxy(SCALE_X(623), SCALE_Y(67), "360°");
    ege_outtextxy(SCALE_X(821), SCALE_Y(67), "00100");
    ege_outtextxy(SCALE_X(954), SCALE_Y(67), "0000");

    // drawallGear 函数内容
    auto drawGear2 = [&](int centerX, int centerY, int radius) {
        int numTeeth = 8;
        double angleStep = 2 * M_PI / numTeeth;
        double innerRadius = radius * 0.9;
        double outerRadius = radius * 1.2;
        setcolor(EGERGB(59, 63, 67));
        int points[36];
        int pointIndex = 0;
        for (int i = 0; i <= numTeeth; ++i) {
            double angle = i * angleStep;
            points[pointIndex++] = SCALE_X(centerX) + SCALE_W(innerRadius) * cos(angle);
            points[pointIndex++] = SCALE_Y(centerY) + SCALE_H(innerRadius) * sin(angle);
            if (i < numTeeth) {
                points[pointIndex++] = SCALE_X(centerX) + SCALE_W(outerRadius) * cos(angle + angleStep / 2);
                points[pointIndex++] = SCALE_Y(centerY) + SCALE_H(outerRadius) * sin(angle + angleStep / 2);
            }
        }
        setfillstyle(SOLID_FILL, EGERGB(109, 113, 121));
        fillpoly(numTeeth * 2 + 1, points);
        };

    auto drawGear = [&](int centerX, int centerY, int radius) {
        int numTeeth = 8;
        double angleStep = 2 * M_PI / numTeeth;
        setcolor(EGERGB(160, 160, 160));
        setlinewidth(SCALE_W(1));
        for (int i = 0; i < numTeeth; ++i) {
            double startAngle = i * angleStep;
            double endAngle = (i + 1) * angleStep;
            int startX = SCALE_X(centerX) + SCALE_W(radius) * cos(startAngle);
            int startY = SCALE_Y(centerY) + SCALE_H(radius) * sin(startAngle);
            int endX = SCALE_X(centerX) + SCALE_W(radius) * cos(endAngle);
            int endY = SCALE_Y(centerY) + SCALE_H(radius) * sin(endAngle);
            int peakX = SCALE_X(centerX) + SCALE_W(radius * 1.2) * cos((startAngle + endAngle) / 2);
            int peakY = SCALE_Y(centerY) + SCALE_H(radius * 1.2) * sin((startAngle + endAngle) / 2);
            ege_line(startX, startY, peakX, peakY);
            ege_line(peakX, peakY, endX, endY);
        }
        };

    drawGear(659, 168, 31);
    setlinewidth(SCALE_W(1));
    setfillcolor(EGERGB(31, 33, 35));
    setcolor(EGERGB(0, 0, 0));
    ege_fillcircle(SCALE_X(64), SCALE_Y(171), SCALE_W(20));
    ege_circle(SCALE_X(64), SCALE_Y(171), SCALE_W(20));
    setfillcolor(EGERGB(92, 94, 98));
    setcolor(EGERGB(40, 40, 40));
    ege_fillcircle(SCALE_X(54), SCALE_Y(171), SCALE_W(19));
    ege_circle(SCALE_X(54), SCALE_Y(171), SCALE_W(19));
    for (int i = 1; i < 17; i++) {
        drawGear2(44 - i / 2, 171, 19);
    }
    ege_fillcircle(SCALE_X(205), SCALE_Y(198), SCALE_W(19));
    ege_circle(SCALE_X(205), SCALE_Y(198), SCALE_W(19));
    for (int i = 1; i < 12; i++) {
        drawGear2(199 - i / 2, 198, 19);
    }
    ege_fillcircle(SCALE_X(365), SCALE_Y(198), SCALE_W(19));
    ege_circle(SCALE_X(365), SCALE_Y(198), SCALE_W(19));
    for (int i = 1; i < 8; i++) {
        drawGear2(359 - i / 2, 198, 19);
    }
    ege_fillcircle(SCALE_X(855), SCALE_Y(171), SCALE_W(19));
    ege_circle(SCALE_X(855), SCALE_Y(171), SCALE_W(19));
    for (int i = 1; i < 8; i++) {
        drawGear2(860 + i / 2, 171, 19);
    }
    ege_fillcircle(SCALE_X(1132), SCALE_Y(198), SCALE_W(19));
    ege_circle(SCALE_X(1132), SCALE_Y(198), SCALE_W(19));
    for (int i = 1; i < 8; i++) {
        drawGear2(1140 + i / 2, 198, 19);
    }
    ege_fillcircle(SCALE_X(1293), SCALE_Y(198), SCALE_W(19));
    ege_circle(SCALE_X(1293), SCALE_Y(198), SCALE_W(19));
    for (int i = 1; i < 10; i++) {
        drawGear2(1300 + i / 2, 197, 19);
    }
    setfillcolor(EGERGB(31, 33, 35));
    setcolor(EGERGB(0, 0, 0));
    ege_fillcircle(SCALE_X(1390), SCALE_Y(171), SCALE_W(20));
    ege_circle(SCALE_X(1390), SCALE_Y(171), SCALE_W(20));
    setfillcolor(EGERGB(92, 94, 98));
    setcolor(EGERGB(40, 40, 40));
    ege_fillcircle(SCALE_X(1400), SCALE_Y(171), SCALE_W(19));
    ege_circle(SCALE_X(1400), SCALE_Y(171), SCALE_W(19));
    for (int i = 1; i < 16; i++) {
        drawGear2(1413 + i / 2, 171, 19);
    }

    // drawsrew 函数内容
    setcolor(BLACK);
    setlinewidth(SCALE_W(2));
    ege_point center{ SCALE_X(533), SCALE_Y(23) };
    ege_point center2{ SCALE_X(666), SCALE_Y(23) };
    ege_point center3{ SCALE_X(770), SCALE_Y(45) };
    ege_point center4{ SCALE_X(880), SCALE_Y(23) };
    ege_setpattern_ellipsegradient(
        center,
        EGERGB(70, 80, 89),
        SCALE_X(517),
        SCALE_Y(11),
        SCALE_W(30),
        SCALE_H(30),
        EGERGB(0, 0, 0)
    );
    ege_circle(SCALE_X(530), SCALE_Y(26), SCALE_W(13));
    ege_fillrect(SCALE_X(517), SCALE_Y(11), SCALE_W(30), SCALE_H(30));
    ege_setpattern_ellipsegradient(
        center2,
        EGERGB(70, 80, 89),
        SCALE_X(641), SCALE_Y(9),
        SCALE_W(30), SCALE_H(30),
        EGERGB(0, 0, 0)
    );
    ege_fillrect(SCALE_X(641), SCALE_Y(9), SCALE_W(30), SCALE_H(30));
    ege_circle(SCALE_X(656), SCALE_Y(23), SCALE_W(13));
    ege_circle(SCALE_X(760), SCALE_Y(42), SCALE_W(13));
    ege_circle(SCALE_X(868), SCALE_Y(25), SCALE_W(13));
    ege_setpattern_ellipsegradient(
        center3,
        EGERGB(70, 80, 89),
        SCALE_X(747), SCALE_Y(30),
        SCALE_W(26), SCALE_H(26),
        EGERGB(0, 0, 0)
    );
    ege_fillrect(SCALE_X(746), SCALE_Y(30), SCALE_W(26), SCALE_H(26));
    ege_setpattern_ellipsegradient(
        center4,
        EGERGB(70, 80, 89),
        SCALE_X(855), SCALE_Y(11),
        SCALE_W(26), SCALE_H(26),
        EGERGB(0, 0, 0)
    );
    ege_fillrect(SCALE_X(855), SCALE_Y(11), SCALE_W(30), SCALE_H(30));
}
//右下方机械表
void drawFrameND(double x, double y, double w, double h) {
    ege_enable_aa(TRUE);

    // 计算缩放比例
    double scaleX = w / 367.0;
    double scaleY = h / 879.0;

    // 绘制主体框架
    setfillcolor(EGERGB(67, 74, 78));
    ege_point points1[] = {
        {x + 71 * scaleX, y + 87 * scaleY},
        {x + 288 * scaleX, y + 87 * scaleY},
        {x + 340 * scaleX, y + 138 * scaleY},
        {x + 340 * scaleX, y + 344 * scaleY},
        {x + 288 * scaleX, y + 396 * scaleY},
        {x + 71 * scaleX, y + 396 * scaleY},
        {x + 19 * scaleX, y + 344 * scaleY},
        {x + 19 * scaleX, y + 138 * scaleY}
    };
    ege_fillpoly(8, points1);

    // 绘制边框
    setcolor(EGERGB(49, 55, 59));
    setlinewidth(9.0 * scaleX);
    ege_point points3[] = {
        {x + 71 * scaleX, y + 87 * scaleY},
        {x + 288 * scaleX, y + 87 * scaleY},
        {x + 340 * scaleX, y + 138 * scaleY},
        {x + 340 * scaleX, y + 344 * scaleY},
        {x + 288 * scaleX, y + 396 * scaleY},
        {x + 71 * scaleX, y + 396 * scaleY}
    };
    ege_drawpoly(6, points3);

    setcolor(EGERGB(81, 88, 93));
    ege_point points4[] = {
        {x + 71 * scaleX, y + 396 * scaleY},
        {x + 19 * scaleX, y + 344 * scaleY},
        {x + 19 * scaleX, y + 138 * scaleY},
        {x + 71 * scaleX, y + 87 * scaleY}
    };
    ege_drawpoly(4, points4);

    setcolor(EGERGB(28, 31, 33));
    setlinewidth(2.0 * scaleX);
    ege_point points2[] = {
        {x + 68 * scaleX, y + 84 * scaleY},
        {x + 290 * scaleX, y + 84 * scaleY},
        {x + 342 * scaleX, y + 134 * scaleY},
        {x + 342 * scaleX, y + 345 * scaleY},
        {x + 290 * scaleX, y + 399 * scaleY},
        {x + 68 * scaleX, y + 399 * scaleY},
        {x + 16 * scaleX, y + 345 * scaleY},
        {x + 16 * scaleX, y + 134 * scaleY},
        {x + 71 * scaleX, y + 83 * scaleY}
    };
    ege_drawpoly(9, points2);

    // 绘制表盘背景
    setfillcolor(EGERGB(92, 97, 99));
    ege_fillroundrect(
        x + 63 * scaleX, y + 129 * scaleY,
        227 * scaleX, 227 * scaleY,
        20 * scaleX
    );

    setfillcolor(EGERGB(0, 0, 0));
    ege_fillroundrect(
        x + 67 * scaleX, y + 133 * scaleY,
        220 * scaleX, 220 * scaleY,
        20 * scaleX
    );

    // 绘制按钮
    setfillcolor(EGERGB(10, 10, 10));
    ege_fillroundrect(
        x + 91 * scaleX, y + 94 * scaleY,
        50 * scaleX, 25 * scaleY,
        5 * scaleX
    );
    ege_fillroundrect(
        x + 215 * scaleX, y + 94 * scaleY,
        50 * scaleX, 25 * scaleY,
        5 * scaleX
    );
    ege_fillroundrect(
        x + 34 * scaleX, y + 156 * scaleY,
        25 * scaleX, 50 * scaleY,
        5 * scaleX
    );
    ege_fillroundrect(
        x + 34 * scaleX, y + 250 * scaleY,
        25 * scaleX, 50 * scaleY,
        5 * scaleX
    );
    ege_fillroundrect(
        x + 91 * scaleX, y + 356 * scaleY,
        50 * scaleX, 25 * scaleY,
        5 * scaleX
    );

    // 绘制大按钮
    setfillcolor(EGERGB(32, 33, 33));
    ege_fillroundrect(
        x + 73 * scaleX, y + 460 * scaleY,
        64 * scaleX, 64 * scaleY,
        9 * scaleX
    );
    ege_fillroundrect(
        x + 221 * scaleX, y + 460 * scaleY,
        64 * scaleX, 64 * scaleY,
        9 * scaleX
    );

    setcolor(EGERGB(0, 0, 0));
    ege_roundrect(
        x + 73 * scaleX, y + 460 * scaleY,
        64 * scaleX, 64 * scaleY,
        9 * scaleX
    );
    ege_roundrect(
        x + 221 * scaleX, y + 460 * scaleY,
        64 * scaleX, 64 * scaleY,
        9 * scaleX
    );

    setcolor(EGERGB(134, 138, 140));
    setlinewidth(3.0 * scaleX);
    ege_roundrect(
        x + 70 * scaleX, y + 457 * scaleY,
        70 * scaleX, 70 * scaleY,
        11 * scaleX
    );
    ege_roundrect(
        x + 218 * scaleX, y + 457 * scaleY,
        70 * scaleX, 70 * scaleY,
        11 * scaleX
    );
}

void drawdialND(double x, double y, double w, double h) {
    double scaleX = w / 367.0;
    double scaleY = h / 879.0;

    ege_enable_aa(TRUE);
    setcolor(EGERGB(134, 138, 140));
    setfont(16 * scaleX, 5 * scaleX, "MS UI Gothic");
    ege_outtextxy(x + 105 * scaleX, y + 97 * scaleY, "APP");
    ege_outtextxy(x + 221 * scaleX, y + 97 * scaleY, "HP/IN");
    ege_outtextxy(x + 226 * scaleX, y + 360 * scaleY, "BARO");
    ege_outtextxy(x + 103 * scaleX, y + 366 * scaleY, "RST");

    setfont(20 * scaleX, 8 * scaleX, "MS UI Gothic");
    ege_outtextxy(x + 41 * scaleX, y + 171 * scaleY, "+");
    ege_outtextxy(x + 41 * scaleX, y + 270 * scaleY, "-");
}

void drawcircleND(double x, double y, double w, double h, double circleX, double circleY) {
    double scaleX = w / 367.0;
    double scaleY = h / 879.0;

    setlinewidth(3 * scaleX);
    setcolor(EGERGB(40, 41, 41));
    ege_circle(x + circleX * scaleX + 1 * scaleX, y + circleY * scaleY, 14 * scaleX);

    setlinewidth(2 * scaleX);
    setfillcolor(EGERGB(66, 72, 77));
    ege_fillcircle(x + circleX * scaleX, y + circleY * scaleY, 14 * scaleX);

    setcolor(EGERGB(30, 31, 31));
    ege_circle(x + circleX * scaleX, y + circleY * scaleY, 13 * scaleX);

    setfillcolor(EGERGB(55, 61, 66));
    ege_fillcircle(x + circleX * scaleX, y + circleY * scaleY, 6 * scaleX);

    setcolor(EGERGB(30, 31, 31));
    ege_circle(x + circleX * scaleX, y + circleY * scaleY, 6 * scaleX);
}

void drawButtonND(double x, double y, double w, double h) {
    double scaleX = w / 367.0;
    double scaleY = h / 879.0;

    setfillcolor(EGERGB(67, 74, 78));
    ege_fillcircle(x + 280 * scaleX, y + 343 * scaleY, 28 * scaleX);

    for (double i = 0; i <= 20; i++) {
        setfillcolor(EGERGB(43, 48, 51));
        ege_fillcircle(
            x + 290 * scaleX - i / 2.5 * scaleX,
            y + 356 * scaleY - i / 1.5 * scaleY,
            19 * scaleX
        );
    }

    setlinewidth(3 * scaleX);
    setfillcolor(EGERGB(93, 95, 97));
    ege_fillcircle(x + 290 * scaleX, y + 356 * scaleY, 17 * scaleX);

    setcolor(EGERGB(102, 104, 105));
    ege_circle(x + 290 * scaleX, y + 356 * scaleY, 18 * scaleX);
}

void drawNDbackground(double x, double y, double w, double h) {
    setfillcolor(EGERGB(67, 75, 82));
    ege_fillrect(x, y, w, h);

    double scaleX = w / 367.0;
    double scaleY = h / 879.0;

    setcolor(EGERGB(134, 138, 140));
    setfont(27 * scaleX, 9 * scaleX, "MS UI Gothic");
    ege_outtextxy(x + 84 * scaleX, y + 599 * scaleY, "DISPLAY CONFIG");

    setfont(17 * scaleX, 6 * scaleX, "MS UI Gothic");
    ege_outtextxy(x + 77 * scaleX, y + 419 * scaleY, "OIS TO");
    ege_outtextxy(x + 218 * scaleX, y + 419 * scaleY, "DISPALY");
    ege_outtextxy(x + 73 * scaleX, y + 437 * scaleY, "CENTER");
    ege_outtextxy(x + 227 * scaleX, y + 438 * scaleY, "CYCLE");

    // 绘制四个钉子
    drawcircleND(x, y, w, h, 33, 96);
    drawcircleND(x, y, w, h, 33, 388);
    drawcircleND(x, y, w, h, 331, 96);
    drawcircleND(x, y, w, h, 331, 388);
}

void drawInnerScaleAndNumbersND(double x, double y, double w, double h, double target_heading) {
    double scaleX = w / 367.0;
    double scaleY = h / 879.0;

    double dialRadius = 76 * scaleX;
    double centerX = x + 174 * scaleX;
    double centerY = y + 235 * scaleY;

    ege_enable_aa(TRUE);
    setcolor(EGEARGB(255, 255, 255, 255));
    setlinewidth(1 * scaleX);

    // 绘制小刻度（5°间隔）
    for (double i = 0; i < 360; i += 5.0) {
        double angle = (i - target_heading + 90.0) * M_PI / 180.0;
        const double r_inner = dialRadius;
        const double r_outer = dialRadius - 3 * scaleX;

        setcolor(EGEARGB(255, 255, 255, 255));
        ege_line(
            centerX + r_inner * cos(angle), centerY + r_inner * sin(angle),
            centerX + r_outer * cos(angle), centerY + r_outer * sin(angle)
        );
    }

    // 绘制大刻度（10°间隔）和数字
    setlinewidth(1 * scaleX);
    for (int i = 0; i < 360; i += 10) {
        double angle = (i - target_heading + 90.0) * M_PI / 180.0;
        const double r_inner = dialRadius;
        const double r_outer = dialRadius - 6 * scaleX;

        ege_line(
            centerX + r_inner * cos(angle), centerY + r_inner * sin(angle),
            centerX + r_outer * cos(angle), centerY + r_outer * sin(angle)
        );

        // 绘制旋转数字
        int value = (18 + i / 10) % 36;
        if ((value < 36) && (value % 3 == 0)) {
            char numStr[5];
            snprintf(numStr, sizeof(numStr), "%d", value);

            const double text_radius = dialRadius - 7.0 * scaleX;
            const double textX = centerX + text_radius * cos(angle);
            const double textY = centerY + text_radius * sin(angle);

            double text_rotation = (i - target_heading);
            int escapement = static_cast<int>(text_rotation * 10.0);

            setfont(
                -15.0 * scaleX, 0.0, L"MS UI Gothic",
                1800 - escapement, 1800 - escapement,
                FW_NORMAL, FALSE, FALSE, FALSE
            );

            settextjustify(CENTER_TEXT, CENTER_TEXT);
            ege_drawtext(numStr, textX, textY);
        }
    }
}

void drawPlaneND(double x, double y, double w, double h) {
    double scaleX = w / 367.0;
    double scaleY = h / 879.0;
    double size = 0.6 * scaleX;
    double planeY = y - 95 * scaleY;

    ege_point points1[] = {
        {x + (int)(244 * scaleX - 2 * size), planeY + (int)(400 * size)},
        {x + (int)(244 * scaleX + 2 * size), planeY + (int)(400 * size)},
        {x + (int)(244 * scaleX + 2 * size), planeY + (int)(415 * size)},
        {x + (int)(244 * scaleX + 27 * size), planeY + (int)(415 * size)},
        {x + (int)(244 * scaleX + 27 * size), planeY + (int)(418 * size)},
        {x + (int)(244 * scaleX + 2 * size), planeY + (int)(418 * size)},
        {x + (int)(244 * scaleX + 2 * size), planeY + (int)(443 * size)},
        {x + (int)(244 * scaleX + 12 * size), planeY + (int)(443 * size)},
        {x + (int)(244 * scaleX + 12 * size), planeY + (int)(446 * size)},
        {x + (int)(244 * scaleX + 2 * size), planeY + (int)(446 * size)},
        {x + (int)(244 * scaleX + 2 * size), planeY + (int)(451 * size)},
        {x + (int)(244 * scaleX - 2 * size), planeY + (int)(451 * size)},
        {x + (int)(244 * scaleX - 2 * size), planeY + (int)(446 * size)},
        {x + (int)(244 * scaleX - 12 * size), planeY + (int)(446 * size)},
        {x + (int)(244 * scaleX - 12 * size), planeY + (int)(443 * size)},
        {x + (int)(244 * scaleX - 2 * size), planeY + (int)(443 * size)},
        {x + (int)(244 * scaleX - 2 * size), planeY + (int)(418 * size)},
        {x + (int)(244 * scaleX - 27 * size), planeY + (int)(418 * size)},
        {x + (int)(244 * scaleX - 27 * size), planeY + (int)(415 * size)},
        {x + (int)(244 * scaleX - 2 * size), planeY + (int)(415 * size)}
    };

    setfillcolor(EGERGB(255, 255, 0));
    ege_fillpoly(20, points1);
}


void drawrightND(double x, double y, double width, double height, double current_heading) {


    //initgraph(800, 900);
    setrendermode(RENDER_MANUAL);
    // setbkcolor(EGERGB(0, 0, 0));
    double scale = width / 367;
    //current_heading = 0;


    drawNDbackground(x, y, width, height);
    drawFrameND(x, y, width, height);

    drawButtonND(x, y, width, height);
    drawdialND(x, y, width, height);
    drawInnerScaleAndNumbersND(x, y, width, height, current_heading);
    drawPlaneND(x - 70 * scale, y + 80 * scale, width, height);



}